package task4;

import com.sun.xml.internal.ws.policy.privateutil.PolicyUtils;

import javax.swing.plaf.basic.BasicFormattedTextFieldUI;
import java.io.*;

/**
 * @author Administrator
 * 1:基本字节流一次读写一个字节，共耗时22097毫秒
 * 2:基本字节流一次读写一个字节数组，共耗时37毫秒
 * 3:字节缓冲流一次读写一个字节，共耗时209毫秒
 * 4:字节缓冲流一次读写一个字节数组，共耗时16毫秒
 */
public class Copy4Methods {
    public static void main(String[] args) throws IOException{
        long start = System.currentTimeMillis();
        // method1("D:\\copy.mp4","copy1.mp4");
         method2("D:\\copy.mp4","copy2.mp4");
        // method3("D:\\copy.mp4","copy3.mp4");
        //method4("D:\\copy.mp4","copy.mp4");
        long end =System.currentTimeMillis();
        System.out.println("共耗时："+(end-start)+"毫秒");
    }



    private static void method1(String s, String s1) throws IOException{
        FileInputStream fis=new FileInputStream(s);
        FileOutputStream fos=new FileOutputStream(s1);

        int len=0;
        while ((len=fis.read())!=-1){
            fos.write(len);
        }
        fis.close();
        fos.close();
    }

    private static void method2(String s, String s1) throws  IOException{
        FileInputStream fis=new FileInputStream(s);
        FileOutputStream fos=new FileOutputStream(s1);

        byte[] bys=new byte[1024];
        int len=0;
        while ((len=fis.read(bys))!=-1){
            fos.write(bys,0,len);
        }
        fis.close();
        fos.close();
    }

    private static void method3(String s, String s1) throws IOException{
        BufferedInputStream bis=new BufferedInputStream(new FileInputStream(s));
        BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream(s1));
        int len=0;
        while ((len=bis.read())!=-1){
            bos.write(len);
        }
        bos.close();
        bis.close();
    }

    private static void method4(String s, String s1)throws IOException {
        BufferedInputStream bis=new BufferedInputStream(new FileInputStream(s));
        BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream(s1));
        byte[] bys=new byte[1024];
        int len=0;
        while ((len=bis.read(bys))!=-1){
            bos.write(bys,0,len);
        }
        bos.close();
        bis.close();
    }



}
